package gudao.red.protobuf;

import gudao.red.protobuf.PersonFactory.Addr;
import gudao.red.protobuf.PersonFactory.Person;
import gudao.red.protobuf.PersonFactory.Person.Builder;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {

	public static void main(String[] args) throws UnknownHostException, IOException {
		
		
		Socket socket = new Socket("127.0.0.1", 3030);
		Builder person = Person.newBuilder();
		Addr.Builder addr = Addr.newBuilder();
		addr.setContry("china").setCity("shenzhen");
		 person.setId(1).setAge(12).setName("ccf");
	     person.setAddr(addr);
	     byte[] messageBody = person.build().toByteArray();
	     byte[] message = new byte[messageBody.length+1];
	     message[0]=(byte) messageBody.length;
	     System.arraycopy(messageBody, 0, message, 1, messageBody.length);
	     System.out.println("mesageBody length:===="+message[0]);
	     socket.getOutputStream().write(message);
	}

}
